<template>
	<view class="blogitem">
		<!-- 头部用户信息 -->
		<view class="head">
			<view class="userinfo">
				<!-- 右边头像 -->
				<view class="avatar">
					<image :src="giveAvatar(item)" mode="aspectFill"></image>
				</view>
				<!-- 右边用户名称 -->
				<view class="name">
					{{getName(item)}}
				</view>
				<!-- 右边时间  定制格式化 -->
				<view class="time">
					<uni-dateformat :date="item.publish_date" format="MM月dd hh:mm" :threshold="[60000,3600000*24*30]">
					</uni-dateformat>
				</view>
			</view>
			<!-- 左边 三个点  更多 -->
			<view class="more" @click="clickMore">
				<text class="iconfont icon-ellipsis"></text>
			</view>
		</view>
		<!-- 中间内容 -->
		<view class="body">
			<!-- 上 标题 -->
			<view class="title" @click="goDetail">{{item.title}}</view>
			<!-- 中 内容 -->
			<view class="text" @click="goDetail">
				<view class="t">{{item.description}}</view>
			</view>
			<!-- 下 缩略图 -->
			<view class="piclist">
				<view class="pic" :class="picArr.length==1 ? 'only': ''" v-for="(pic,index) in item.picurls"
					:key="index">
					<image :src="pic" @click="clickPic" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<!-- 底部 信息内容 -->
		<view class="info">
			<!-- 游览量 -->
			<view class="box">
				<text class="iconfont icon-a-27-liulan"></text> <text>{{item.view_count}}</text>
			</view>
			<!-- 评论数 -->
			<view class="box" @click="goDetail">
				<text class="iconfont icon-a-5-xinxi"></text>
				<text>{{item.comment_count && item.comment_count>0 ? item.comment_count : '评论'}}</text>
			</view>
			<!-- 点赞量 -->
			<view class="box">
				<text class="iconfont icon-a-106-xihuan"></text>
				<text>{{item.like_count ? item.like_count : '点赞'}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getName,
		giveAvatar
	} from "../../utils/tool.js"
	export default {
		name: "blog-item",
		props: {
			item: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {
				picArr: [1, 2, 3]
			};
		},
		onLoad() {

		},
		methods: {
			getName,
			giveAvatar,
			//单击图片
			clickPic(index) {
				console.log("点了图片............", this.item.picurls[0])
				uni.previewImage({
					urls: this.item.picurls,
					// longPressActions: {
					// 	itemList: ['发送给朋友', '保存图片', '收藏'],
					// 	success: function(data) {
					// 		console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
					// 	},
					// 	fail: function(err) {
					// 		console.log(err.errMsg);
					// 	}
					// }
				});
				// uni.previewImage({
				// 	urls: this.item.picurls,
				// 	current: index
				// })
			},
			//点击跳转到详情
			goDetail() {
				console.log("点了第几个：", this.item._id)
				uni.navigateTo({
					url: "/pages/detail/detail?id=" + this.item._id
				})
			},


		}

	}
</script>

<style lang="scss">
	.blogitem {
		.head {
			display: flex;
			font-size: 32rpx;
			align-items: center;
			justify-content: space-between;

			.userinfo {
				display: flex;
				align-items: center;

				.avatar {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					border-radius: 50%;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
						display: block;
					}
				}

				.name {
					color: #222;
					padding-left: 10rpx;
				}

				.time {
					color: #888;
					font-size: 22rpx;
					padding-left: 20rpx;
				}
			}

			.more {
				padding: 5rpx;

				.iconfont {
					font-size: 50rpx;
					color: #888;
				}
			}
		}

		.body {
			padding: 15rpx 0 30rpx;

			.title {
				font-size: 44rpx;
				color: #000;
				font-weight: 600;
				text-align: justify;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.text {
				padding-top: 10rpx;
				padding-bottom: 10rpx;
				font-size: 30rpx;
				text-align: justify;
				color: #888;

				.t {
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}

			.piclist {
				display: flex;
				padding-top: 20rpx;

				.pic {
					width: 225rpx;
					height: 225rpx;
					margin-right: 6rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}

					&:first-child {
						border-radius: 20rpx 0 0 20rpx;
					}

					&:last-child {
						border-radius: 0 20rpx 20rpx 0;
					}

					&.only {
						border-radius: 20rpx;
					}
				}
			}
		}

		.info {
			display: flex;
			align-items: center;
			justify-content: space-around;
			font-size: 26rpx;
			color: #333;

			.box {
				display: flex;
				align-items: center;
				padding: 15rpx 0 5rpx;
				flex: 1;
				display: flex;
				justify-content: center;

				.iconfont {
					font-size: 40rpx;
					padding-right: 10rpx;
				}
			}

			.box.active {
				color: #0199FE
			}
		}
	}
</style>